﻿using System;
using BrainTechLLC;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace BrainTechLLC.Silverlight.ClientApplication
{
    public partial class TypeAndMethod : UserControl
    {
        public static readonly DependencyProperty MethodProperty = DependencyProperty.Register(
            "Method",
            typeof(Method),
            typeof(TypeAndMethod),
            new PropertyMetadata(null, new PropertyChangedCallback(MethodChanged)));

        public Method Method
        {
            get { return (Method)GetValue(MethodProperty); }
            set { SetValue(MethodProperty, value); }
        }

        private static void MethodChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TypeAndMethod t = (TypeAndMethod)d;
            t.Method = e.NewValue as Method;
            if (t.Method == null)
            {
                t.MethodName = string.Empty;
                t.TypeName = string.Empty;
            }
            else
            {
                t.MethodName = t.Method.MethodName;
                t.TypeName = t.Method.TypeName;
            }
        }
        
        public static readonly DependencyProperty TypeNameProperty = DependencyProperty.Register(
            "TypeName",
            typeof(string),
            typeof(TypeAndMethod),
            new PropertyMetadata(null, new PropertyChangedCallback(TypeNameChanged)));

        public string TypeName
        {
            get { return (string)GetValue(TypeNameProperty); }
            set { SetValue(TypeNameProperty, value); }
        }

        private static void TypeNameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TypeAndMethod t = (TypeAndMethod)d;
            t.Dispatcher.BeginInvoke(() => t.cboType.Text = e.NewValue as string);
        }

        public static readonly DependencyProperty MethodNameProperty = DependencyProperty.Register(
            "MethodName",
            typeof(string),
            typeof(TypeAndMethod),
            new PropertyMetadata(null, new PropertyChangedCallback(MethodNameChanged)));

        public string MethodName
        {
            get { return (string)GetValue(MethodNameProperty); }
            set { SetValue(MethodNameProperty, value); }
        }

        private static void MethodNameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TypeAndMethod t = (TypeAndMethod)d;
            t.Dispatcher.BeginInvoke(() => t.cboMethodName.Text = e.NewValue as string);
        }
        
        public TypeAndMethod()
        {
            // Required to initialize variables
            InitializeComponent();
        }
    }
}